{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"https://raw.githubusercontent.com/Qiskit/qiskit-tutorials/master/images/qiskit-heading.png\" width=\"500 px\" align=\"center\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# IBM Q setup\n",
    "This tutorial will walk you through the configuration for your IBM Q Experience account so that, in the future, you are able to run your Quantum Programs in both online simulators as well as real Quantum Computers.\n",
    "\n",
    "We assume you have installed Qiskit if not please look at [qiskit.org](http://www.qiskit.org) or the install [documentation](https://github.com/qiskit/qiskit-tutorial/blob/master/INSTALL.md). \n",
    "\n",
    "To test this run the following commands"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import qiskit"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Execute on a Real Device (IBM Q Experience)\n",
    "\n",
    "You can use Qiskit to run your circuits on real quantum computers using the IBMQ provider. They are small and noisy but are advancing at a fast pace. In the future, more information will be given regarding this environment, but for now lets go ahead and set it up!\n",
    "\n",
    "To access IBMQ devices, you'll need an API token. For the public Quantum Experience devices, you can generate an API token [here](https://quantumexperience.ng.bluemix.net/qx/account/advanced) (create an account if you don't already have one). For Q Network devices, login to the q-console, click your hub, group, and project, and expand \"Get Access\" to generate your API token and access url."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit import IBMQ # requires qiskit version >= 0.6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After generating your API token, call:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "IBMQ.save_account(\"MY_TOKEN\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For Q Network users, you'll also need to include your access url:\n",
    "\n",
    "`IBMQ.save_account('MY_TOKEN', 'URL')`\n",
    "\n",
    "This will store your IBMQ credentials in a local file. Unless your registration information has changed, you only need to do this once. \n",
    "\n",
    "You may now (or in any other exercise) load your accounts by calling:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "IBMQ.load_account()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Which Backends are available right now?\n",
    "A backend is either an online Quantum simulator or a Quantum Computer.\n",
    "\n",
    "This is how you can list them by name:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ibmqx4\n",
      "ibmqx5\n",
      "ibmqx2\n",
      "ibmq_16_melbourne\n",
      "ibmq_qasm_simulator\n"
     ]
    }
   ],
   "source": [
    "for backend in IBMQ.backends():\n",
    "    print(backend)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Additionally, you can get all of their configurations, like so:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'local': False, 'name': 'ibmqx4', 'version': '1.2.0', 'description': '5 qubit transmon bowtie chip 3', 'gate_set': 'SU2+CNOT', 'basis_gates': 'u1,u2,u3,cx,id', 'online_date': '2017-09-18T00:00:00.000Z', 'chip_name': 'Raven', 'deleted': False, 'url': 'https://ibm.biz/qiskit-ibmqx4', 'internal_id': '5ae875670f020500393162b3', 'simulator': False, 'allow_q_object': False, 'n_qubits': 5, 'coupling_map': [[1, 0], [2, 0], [2, 1], [3, 2], [3, 4], [4, 2]]}\n"
     ]
    }
   ],
   "source": [
    "backend_0 = IBMQ.backends()[0] # retrieve the Backend at index 0\n",
    "print(backend_0.configuration())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Go check its specification at https://ibm.biz/qiskit-ibmqx4\n"
     ]
    }
   ],
   "source": [
    "print(\"Go check its specification at %s\" % backend_0.configuration()[\"url\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "That's it for this week, if you have reached this point your local machine is now ready for the next steps 💪"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
